package org.hackystat.iw.projectoverviewer.page.treemap;

/*
 * This code is highly inspired by Object Lab.
 * 
 * www.ObjectLab.co.uk
 */

import java.io.Serializable;
import javax.swing.JToolTip;
import net.sf.jtreemap.swing.IToolTipBuilder;
import net.sf.jtreemap.swing.JTreeMap;

/**
 * Builder for the tool tip.
 * 
 * @author Laurent DUTHEIL
 * @author Jianfei Liao
 * @author Nathan Britton 
 */
class IWToolTipBuilder implements IToolTipBuilder, Serializable {
  private static final long serialVersionUID = -1646772942428571187L;

  private JToolTip instance = null;

  private JTreeMap jTreeMap;

  private String weightPrefix;

  private String valuePrefix;

  private boolean showWeight;

  /**
   * Constructor.
   * 
   * @param jTreeMap The JTreeMap instance.
   * @param weightPrefix The prefix for weight.
   * @param valuePrefix The prefix for value.
   * @param showWeight Shows the weight if true, false otherwise.
   */
  public IWToolTipBuilder(final JTreeMap jTreeMap, final String weightPrefix,
      final String valuePrefix, final boolean showWeight) {
    this.jTreeMap = jTreeMap;
    this.weightPrefix = weightPrefix;
    this.valuePrefix = valuePrefix;
    this.showWeight = showWeight;
  }

  /**
   * Gets the tool tip.
   * 
   * @see net.sf.jtreemap.swing.IToolTipBuilder#getToolTip()
   * @return The tool tip.
   */
  public JToolTip getToolTip() {
    if (instance == null) {
      instance = new IWToolTip(this.jTreeMap, this.weightPrefix, this.valuePrefix, this.showWeight);
    }
    return instance;
  }
}
